/**
 * User: alesj
 * Date: 2004.8.23
 * Time: 16:10:04
 */

package com.generalynx.common.utils;

import com.generalynx.common.international.ILanguageFactory;
import com.generalynx.common.components.IComponentFactory;
import org.springframework.beans.factory.InitializingBean;

public class ApplicationFactory implements InitializingBean {

    private static ApplicationFactory applicationFactory = null;
    private IComponentFactory componentFactory = null;
    private ILanguageFactory languageFactory = null;

    private ApplicationFactory() {
    }

    public static ApplicationFactory getInstance() {
        if (applicationFactory == null) {
            applicationFactory = new ApplicationFactory();
        }
        return applicationFactory;
    }

    public static IComponentFactory getComponentFactory() {
        return getInstance().componentFactory;
    }

    //used with Spring bean factory
    public void setComponentFactory(IComponentFactory componentFactory) {
        this.componentFactory = componentFactory;
    }

    public static ILanguageFactory getLanguageFactory() {
        return getInstance().languageFactory;
    }

    //used with Spring bean factory
    public void setLanguageFactory(ILanguageFactory languageFactory) {
        this.languageFactory = languageFactory;
    }

    public void afterPropertiesSet() throws Exception {
        if (componentFactory == null) {
            throw new IllegalArgumentException("Component factory must be set!");
        }
        if (languageFactory == null) {
            throw new IllegalArgumentException("Language factory must be set!");
        }
    }
    
}
